import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
    server: {// 创建代理服务器
    proxy: {
      '/api': {//如果前端请求的接口是/api开头的,则代理到target指定的服务器上
        target: 'http://localhost:8080',
        secure: false,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),//路径重定向,将/api开头的请求路径，替换成''
      }
    }
  }
})
